package cn.afactory.tygz.model.user;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;

/**
 * Created with Android Studio.
 * Title:UserTag
 * Description:
 * Copyright:Copyright (c) 2015
 * Company:和平必胜、正义必胜、人民必胜
 * Author:炎黄子孙
 * Date:15/11/30
 * Time:下午9:39
 * Version 1.0
 */
public class UserTag implements Serializable{
    private static final long serialVersionUID = 4729003600066722628L;
    public int id;

    public String name;

    /**
     * 反序列化函数，用于从json字符串反序列化本类型实例
     */
    public static UserTag deserialize(String json) throws JSONException {
        if (json != null && !json.isEmpty()) {
            return deserialize(new JSONObject(json));
        }
        return null;
    }

    /**
     * 反序列化函数，用于从json节点对象反序列化本类型实例
     */
    public static UserTag deserialize(JSONObject json) throws JSONException {
        if (json != null && json != JSONObject.NULL && json.length() > 0) {
            UserTag result = new UserTag();

            result.id = json.optInt("id");

            if (!json.isNull("name")) {
                result.name = json.optString("name", null);
            }

            return result;
        }
        return null;
    }
}
